let express = require("express");
let app = express();
let path = require("path");

//处理body的中间件
app.use(express.urlencoded());
app.use(express.json());

//查询学生信息接口
app.get("/userinfo/:userid", (request, response) => {
  let { userid } = request.params;
    
  //如果查询失败

  if (userid !== "001") {
    return response.send({
      code: 10001,
      msg: "查询失败",
      data: null,
    });
  }

  //查询成功 响应
  response.send({
    code: 10000,
    msg: "查询成功",
    data: {
      name: "李博",
      age: 18,
      sex: "男",
    },
  });
});

app.get("/1", (req, res) => {
    const filePath = path.resolve(__dirname, "./get请求.html");
    res.sendFile(filePath);
  })

app.listen(8080,()=>{
    console.log("running");
})
